﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class SiteAdmin_FileDelete : xIx.Web.UI.PageBase
{
    public string fp
    {
        get
        {
            object v = ViewState["fp"];
            if (null != v)
            {
                return (string)v;
            }
            else
            {
                return default(string);
            }
        }
        set
        {
            ViewState["fp"] = value;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string s = Request["FK"];
            if (string.IsNullOrEmpty(s))
            {
                Label2.Text = "没有文件。";
                return;
            }
            Label1.Text = s;

            if (!s.StartsWith("/UserFiles/", StringComparison.CurrentCultureIgnoreCase))
            {
                Label2.Text = "只允许删除上传的文件。";
                return;
            }
            string fn = Server.MapPath(s);
            string fn2 = fn + ".fileinfo";
            if (!System.IO.File.Exists(fn))
            {
                Label2.Text = "没有不存在。";
                return;
            }

            if (System.IO.File.Exists(fn2))
            {
                try { Label3.Text = System.IO.File.ReadAllLines(fn2)[0]; }
                catch { }
            }
            fp = fn;
            Button1.Enabled = true;
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string s = fp;
        if (fp.StartsWith(Server.MapPath("/UserFiles/"), StringComparison.CurrentCultureIgnoreCase))
        {
            System.IO.File.Delete(s);
            System.IO.File.Delete(s + ".fileinfo");
            Label2.Text = "删除成功。需要时，请手动刷新文件列表。";
            Button1.Enabled = false;
        }
    }
}
